﻿Public Class LogErrori

    Dim strNameFile As String = ""

    Public Sub New(ByVal inNameFile As String)
        strNameFile = inNameFile
    End Sub

    Public Sub Log(ByVal inNameModule As String, ByVal inNameRoutine As String, ByRef inException As Exception)
        Try
            Dim strTesto As String = ""

            strTesto = String.Format("" &
                                    "Pc: {0} " & vbCrLf &
                                    "Software: {1} " & vbCrLf &
                                    "Module: {2} " & vbCrLf &
                                    "Function: {3} " & vbCrLf &
                                    "Error Desc. : {4} " & vbCrLf &
                                    "Stack : {5} " & vbCrLf &
                                    "Data : {6} " & vbCrLf &
                                    "-----------------------------------------" & vbCrLf & vbCrLf,
                                    Environment.MachineName,
                                    My.Application.Info.Title,
                                    inNameModule,
                                    inNameRoutine,
                                    inException.Message,
                                    inException.StackTrace.ToString,
                                    DateTime.Now
                                    )

            Dim oFileStream As New IO.FileStream(strNameFile, IO.FileMode.Append)
            Dim oStreamWriter As New IO.StreamWriter(oFileStream)
            oStreamWriter.Write(strTesto)
            oStreamWriter.Close()
            oFileStream.Close()
            oStreamWriter = Nothing
            oFileStream = Nothing
        Catch ex As Exception

        End Try
    End Sub

End Class
